package DieSiedler;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.ScrollPane;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.HTMLDocument;
/*
 * BabyBrowser.java
 *
 * Created on 31. Mai 2007, 16:21
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 * Ein simpler Browser der HTML Dokumente zwecks Spielanleitungen etc.
 * @author oliver
 */
public class BabyBrowser extends JFrame implements HyperlinkListener{
    
    /** Creates a new instance of babyBrowser */
    JEditorPane htmlPane;
    private boolean vis = false;
    private int height;
    private int width;
    public BabyBrowser(String startfile, String title, int width, int height, Image icon) {
            this.width=width;
            this.height=height;
            this.setTitle(title);
            htmlPane = new JEditorPane();
            JScrollPane scroll = new JScrollPane(htmlPane);
            scroll.setViewportView(htmlPane);
            htmlPane.setEditable(false);
            this.add(scroll);
            htmlPane.addHyperlinkListener(this);
            this.setSize(width,height);
            this.setIconImage(icon);
            //htmlPane.setContentType("text/html; charset=EUC-JP");
            
        try {
            htmlPane.setPage(getClass().getResource(startfile));           
        } catch (IOException ex) {
             htmlPane.setText("<h1>Can't find files, sorry...<h1>");  
        }
         
      
   
         
    }
   
    public void showBrowser(boolean vis){
        this.vis=vis;
        this.setVisible(vis);
        if(vis){
            this.setSize(width,height);
        }
    }
    
   public void hyperlinkUpdate(HyperlinkEvent event) { 
    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
       try {
           htmlPane.setPage(event.getURL().toString());
       } catch (Exception ex) {
           ex.printStackTrace();
       }
    }
  }
   

    
}


